package com.alibaba.csp.sentinel.dashboard.rule.apollo;

import com.alibaba.csp.sentinel.dashboard.client.SentinelApiClient;
import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.DegradeRuleEntity;
import com.alibaba.csp.sentinel.dashboard.rule.DynamicRulePublisher;
import com.alibaba.fastjson.JSON;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


/**
 * @ClassName DegradeRuleApolloPublisher
 * @Description TODO
 * @Author zhouchao
 * @Date 2020/2/17 20:23
 * @Version 1.0
 */
@Component("degradeRuleApolloPublisher")
public class DegradeRuleApolloPublisher extends AbstractApolloCommonService implements
        DynamicRulePublisher<List<DegradeRuleEntity>> {

    @Autowired
    private SentinelApiClient sentinelApiClient;

    @Override
    public void publish(String appName, List<DegradeRuleEntity> rules) throws Exception {
        /*DegradeRuleEntity degradeRuleEntity = rules.get(0);
        String ip = degradeRuleEntity.getIp();
        Integer port = degradeRuleEntity.getPort();
        boolean flag = sentinelApiClient.setDegradeRuleOfMachine(appName, ip, port, rules);
        if (flag) {
            apolloCommonService.publishRules(appName, degradeDataIdSuffix, JSON.toJSONString(rules));
        }*/
        apolloCommonService.publishRules(appName, degradeDataIdSuffix, JSON.toJSONString(rules));
    }
}
